import React, { Component } from 'react';
import CustomBreadcrumb from '../../components/CustomBreadcrumb';
import AddCompany from './components/AddCompany';
import { hashHistory } from 'react-router';
import { CompanyService } from '../../services'

export default class Company extends Component {
  static displayName = 'Company';

  constructor(props) {
    super(props);
    this.state = {};
  }

  checkAccount = async(value) =>{
    if(!await CompanyService.exist(value)){ return null }
    return "名称重复"
  }

  onSubmit = async(data) =>{
    await CompanyService.save(data)
    hashHistory.push('/company/list')
    return true
  }

  render() {
    const breadcrumb = [
      { text: '公司管理', link: '#/company/list' },
      { text: '新增公司', link: '#/company/add' },
    ];
    return (
      <div className="company-page">
        <CustomBreadcrumb dataSource={breadcrumb} />
        <AddCompany checkAccount={this.checkAccount} onSubmit={this.onSubmit}/>
      </div>
    );
  }
}
